package br.ucb.cesbdao.janelas;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import org.apache.log4j.Logger;
import org.jdesktop.swingx.JXDatePicker;

import br.ucb.cesbdao.beans.DadosSessaoUser;
import br.ucb.cesbdao.beans.Trabalhador;
import br.ucb.cesbdao.controller.ControladorJanelas;
import br.ucb.cesbdao.enuns.EnumControleJanela;
import br.ucb.cesbdao.enuns.EnumMensagens;
import br.ucb.cesbdao.enuns.EnumTitulo;
import br.ucb.cesbdao.model.AtendidoModel;
import br.ucb.cesbdao.model.AtendimentoModel;
import br.ucb.cesbdao.model.TrabalhadorModel;
import br.ucb.cesbdao.model.impl.AtendidoModelImpl;
import br.ucb.cesbdao.model.impl.AtendimentoModelImpl;
import br.ucb.cesbdao.model.impl.TrabalhadorModelImpl;
import br.ucb.cesbdao.modeloTabelas.ModeloTabelaAtendimentoGerencia;
import br.ucb.cesbdao.modeloTabelas.ModeloTabelaPaciente;
import br.ucb.cesbdao.servicos.DateUtil;
import br.ucb.cesbdao.servicos.Validadores;
import br.ucb.cesbdao.utilBeans.RelatoriosUtil;
import br.ucb.cesbdao.utilBeans.TrabalhadorUtil;
import br.ucb.cesbdao.visao.Visao;

public class JanelaAFI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtEmail;
	private JTextField txtCodSocio;
	private JPanel painelAlteraPerfil;
	private JLabel lblCdScio;
	private JLabel lblEmail;
	private JLabel lblTelefones;
	private JLabel lblEndereo;
	private JTextField txtEndereco;
	private JLabel lblSexo;
	private JRadioButton rdbtnMasculino;
	private JRadioButton rdbtnFeminino;
	private JLabel lblDataDeNasc;
	private JFormattedTextField ftxtDataNasc;
	private JLabel lblNome;
	private JLabel lblCpf;
	private JTextField txtNome;
	private JFormattedTextField ftxtCPF;
	private JPanel painelTelefones;
	private JFormattedTextField ftxtTel1;
	private JFormattedTextField ftxtTel2;
	private JFormattedTextField ftxtTel3;
	private JFormattedTextField ftxtTel4;
	private JFormattedTextField ftxtTel5;
	private JFormattedTextField ftxtTel6;
	private JLabel lblSeparador;
	private JLabel lblSeparador2;
	private JLabel lblSeparador3;
	private JLabel lblSeparador4;
	private final ButtonGroup btnGroupSexo = new ButtonGroup();
	private JButton btnAlterar;
	private JButton btnCancelar;
	private JButton btnAlterarSenha;
	private JLabel lblQuant_1;
	private static Trabalhador atendente;
	private JMenu mnAtendimentos;
	private JPanel painelInicial;
	private JPanel painelAtendimentos;
	private JTable jtableAtendimentos;
	private ModeloTabelaAtendimentoGerencia modeloTabelaAtendimentoGerencia = new ModeloTabelaAtendimentoGerencia();
	private JLabel lblData;
	private JXDatePicker dpSistemaAFI;
	private JPanel cabecario;
	private JPanel painelData;
	private JPanel painelQuantAtned;
	private JLabel lblQuantidadeDeAtendimentos_1;
	private JLabel lblQuantAtend;
	private JPanel painelRelatorio;
	private final ButtonGroup btnGroupTipoRelatorioQuant = new ButtonGroup();
	private JRadioButton rdbnQuantAtendimento;
	private JRadioButton rdbnQuantFrequencia;
	private JXDatePicker dpInicioRQuantInicio;
	private JXDatePicker dpInicioRQuantFim;
	private JPanel painelAtendidoRelatorio;
	private JLabel lblAtendidoRelatorio;
	private JTextField txtBuscaAtendido;
	private JPanel painelPeriodoAtendidoR;
	private JLabel lblInformePeriodo;
	private JXDatePicker dpRAtendidoInicio;
	private JLabel lblDataIniRAtendido;
	private JLabel lblDataFimRAtendido;
	private JXDatePicker dpRAtendidoFim;
	private JScrollPane spAtendidoRelatorio;
	private JButton btnGeraRelatorioAtendido;
	private JTable jtAtendidoRelatorio;
	private ModeloTabelaPaciente modeloTabelaPaciente = new ModeloTabelaPaciente();
	static Logger logger;
	

	/**
	 * Create the frame.
	 */
	public JanelaAFI() {
		setTitle(EnumTitulo.TITULO_PRINCIPAL.getTitulo());
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnPerfil = new JMenu("Perfil");
		menuBar.add(mnPerfil);
		
		JMenuItem mntmAlterarPerfil = new JMenuItem("Alterar Perfil");
		mntmAlterarPerfil.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setAfi();
				preparaPainelPrincipal();
				painelAlteraPerfil.setVisible(true);
			}
		});
		mnPerfil.add(mntmAlterarPerfil);
		
		mnAtendimentos = new JMenu("Atendimentos");
		menuBar.add(mnAtendimentos);
		
		JMenuItem mntmAtendimentos = new JMenuItem("Gerenciar Atendimentos");
		mntmAtendimentos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				preparaPainelPrincipal();
				painelAtendimentos.setVisible(true);
			}
		});
		mnAtendimentos.add(mntmAtendimentos);
		
		JMenu mnRelatorios = new JMenu("Relatorios");
		menuBar.add(mnRelatorios);
		
		JMenuItem mntmGerarRelatorios = new JMenuItem("Gerar Relatorios");
		mntmGerarRelatorios.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				preparaPainelPrincipal();
				painelRelatorio.setVisible(true);
			}
		});
		mnRelatorios.add(mntmGerarRelatorios);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLayeredPane layeredPane = new JLayeredPane();
		
		painelAlteraPerfil = new JPanel();
		painelAlteraPerfil.setVisible(false);
		painelAlteraPerfil.setBorder(new TitledBorder(null, "Altera Perfil", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		painelRelatorio = new JPanel();
		painelRelatorio.setBorder(new TitledBorder(null, "Relatorios", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		painelRelatorio.setVisible(false);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		GroupLayout gl_painelRelatorio = new GroupLayout(painelRelatorio);
		gl_painelRelatorio.setHorizontalGroup(
			gl_painelRelatorio.createParallelGroup(Alignment.LEADING)
				.addComponent(tabbedPane, GroupLayout.PREFERRED_SIZE, 746, Short.MAX_VALUE)
		);
		gl_painelRelatorio.setVerticalGroup(
			gl_painelRelatorio.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelRelatorio.createSequentialGroup()
					.addComponent(tabbedPane, GroupLayout.PREFERRED_SIZE, 503, Short.MAX_VALUE)
					.addContainerGap())
		);
		
		JPanel painelAtendimeto = new JPanel();
		painelAtendimeto.setBorder(new LineBorder(new Color(0, 0, 0)));
		tabbedPane.addTab("Quantidade", null, painelAtendimeto, null);
		
		JPanel painelFrequencia = new JPanel();
		painelFrequencia.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		JPanel painelTpRelatorio = new JPanel();
		painelTpRelatorio.setBorder(new TitledBorder(null, "Tipo de Relatorio", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		rdbnQuantAtendimento = new JRadioButton("Atendimentos");
		btnGroupTipoRelatorioQuant.add(rdbnQuantAtendimento);
		rdbnQuantAtendimento.setSelected(true);
		
		rdbnQuantFrequencia = new JRadioButton("Frequencia");
		btnGroupTipoRelatorioQuant.add(rdbnQuantFrequencia);
		GroupLayout gl_painelTpRelatorio = new GroupLayout(painelTpRelatorio);
		gl_painelTpRelatorio.setHorizontalGroup(
			gl_painelTpRelatorio.createParallelGroup(Alignment.LEADING)
				.addGap(0, 454, Short.MAX_VALUE)
				.addGap(0, 426, Short.MAX_VALUE)
				.addGroup(gl_painelTpRelatorio.createSequentialGroup()
					.addContainerGap()
					.addComponent(rdbnQuantAtendimento)
					.addGap(18)
					.addComponent(rdbnQuantFrequencia)
					.addContainerGap(220, Short.MAX_VALUE))
		);
		gl_painelTpRelatorio.setVerticalGroup(
			gl_painelTpRelatorio.createParallelGroup(Alignment.LEADING)
				.addGap(0, 61, Short.MAX_VALUE)
				.addGap(0, 29, Short.MAX_VALUE)
				.addGroup(gl_painelTpRelatorio.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelTpRelatorio.createParallelGroup(Alignment.BASELINE)
						.addComponent(rdbnQuantAtendimento)
						.addComponent(rdbnQuantFrequencia))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		painelTpRelatorio.setLayout(gl_painelTpRelatorio);
		
		dpInicioRQuantInicio = new JXDatePicker();
		
		JLabel lblDataIniRQuant = new JLabel("Data Inicio");
		
		JLabel lblDataFimRQuant = new JLabel("Data Fim");
		
		dpInicioRQuantFim = new JXDatePicker();
		GroupLayout gl_painelFrequencia = new GroupLayout(painelFrequencia);
		gl_painelFrequencia.setHorizontalGroup(
			gl_painelFrequencia.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelFrequencia.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelFrequencia.createParallelGroup(Alignment.LEADING)
						.addComponent(painelTpRelatorio, GroupLayout.PREFERRED_SIZE, 454, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_painelFrequencia.createSequentialGroup()
							.addGroup(gl_painelFrequencia.createParallelGroup(Alignment.LEADING)
								.addComponent(dpInicioRQuantInicio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblDataIniRQuant))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_painelFrequencia.createParallelGroup(Alignment.LEADING)
								.addComponent(lblDataFimRQuant, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
								.addComponent(dpInicioRQuantFim, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(264, Short.MAX_VALUE))
		);
		gl_painelFrequencia.setVerticalGroup(
			gl_painelFrequencia.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_painelFrequencia.createSequentialGroup()
					.addGap(10)
					.addComponent(painelTpRelatorio, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addGroup(gl_painelFrequencia.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_painelFrequencia.createSequentialGroup()
							.addComponent(lblDataFimRQuant)
							.addGap(6)
							.addComponent(dpInicioRQuantFim, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_painelFrequencia.createSequentialGroup()
							.addComponent(lblDataIniRQuant)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(dpInicioRQuantInicio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGap(122))
		);
		painelFrequencia.setLayout(gl_painelFrequencia);
		
		JButton btnGerarRQauntidade = new JButton("Gerar");
		btnGerarRQauntidade.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(rdbnQuantAtendimento.isSelected()){
					RelatoriosUtil.quantidadeDeAtendimentosByAFI(dpInicioRQuantInicio.getDate(),dpInicioRQuantFim.getDate(),getTrabalhador());
				}else
					RelatoriosUtil.quantidadeDeFaltasByAFI(dpInicioRQuantInicio.getDate(), dpInicioRQuantFim.getDate(), getTrabalhador());
				
			}
		});
		btnGerarRQauntidade.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/Report-48.png")));
		GroupLayout gl_painelAtendimeto = new GroupLayout(painelAtendimeto);
		gl_painelAtendimeto.setHorizontalGroup(
			gl_painelAtendimeto.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_painelAtendimeto.createSequentialGroup()
					.addContainerGap(318, Short.MAX_VALUE)
					.addComponent(btnGerarRQauntidade)
					.addGap(315))
				.addGroup(gl_painelAtendimeto.createSequentialGroup()
					.addGap(12)
					.addComponent(painelFrequencia, GroupLayout.DEFAULT_SIZE, 726, Short.MAX_VALUE)
					.addContainerGap())
		);
		gl_painelAtendimeto.setVerticalGroup(
			gl_painelAtendimeto.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_painelAtendimeto.createSequentialGroup()
					.addContainerGap()
					.addComponent(painelFrequencia, GroupLayout.PREFERRED_SIZE, 187, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 212, Short.MAX_VALUE)
					.addComponent(btnGerarRQauntidade)
					.addContainerGap())
		);
		painelAtendimeto.setLayout(gl_painelAtendimeto);
		
		painelAtendidoRelatorio = new JPanel();
		tabbedPane.addTab("Atendido", null, painelAtendidoRelatorio, null);
		
		lblAtendidoRelatorio = new JLabel("Atendido:");
		
		txtBuscaAtendido = new JTextField();
		txtBuscaAtendido.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				zeraPreencheTabelaAtendidoRelatorio();
			}
		});
		txtBuscaAtendido.setColumns(10);
		
		painelPeriodoAtendidoR = new JPanel();
		painelPeriodoAtendidoR.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		lblInformePeriodo = new JLabel("Informe Periodo");
		
		dpRAtendidoInicio = new JXDatePicker();
		
		lblDataIniRAtendido = new JLabel("Data Inicio");
		
		lblDataFimRAtendido = new JLabel("Data Fim");
		
		dpRAtendidoFim = new JXDatePicker();
		GroupLayout gl_painelPeriodoAtendidoR = new GroupLayout(painelPeriodoAtendidoR);
		gl_painelPeriodoAtendidoR.setHorizontalGroup(
			gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.LEADING)
				.addGap(0, 907, Short.MAX_VALUE)
				.addGroup(gl_painelPeriodoAtendidoR.createSequentialGroup()
					.addGap(19)
					.addGroup(gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.LEADING)
						.addComponent(lblInformePeriodo)
						.addGroup(gl_painelPeriodoAtendidoR.createSequentialGroup()
							.addGroup(gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.LEADING)
								.addComponent(dpRAtendidoInicio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblDataIniRAtendido))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.LEADING)
								.addComponent(lblDataFimRAtendido, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
								.addComponent(dpRAtendidoFim, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(598, Short.MAX_VALUE))
		);
		gl_painelPeriodoAtendidoR.setVerticalGroup(
			gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.TRAILING)
				.addGap(0, 131, Short.MAX_VALUE)
				.addGroup(gl_painelPeriodoAtendidoR.createSequentialGroup()
					.addContainerGap(14, Short.MAX_VALUE)
					.addComponent(lblInformePeriodo)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_painelPeriodoAtendidoR.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_painelPeriodoAtendidoR.createSequentialGroup()
							.addComponent(lblDataFimRAtendido)
							.addGap(6)
							.addComponent(dpRAtendidoFim, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_painelPeriodoAtendidoR.createSequentialGroup()
							.addComponent(lblDataIniRAtendido)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(dpRAtendidoInicio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGap(41))
		);
		painelPeriodoAtendidoR.setLayout(gl_painelPeriodoAtendidoR);
		
		spAtendidoRelatorio = new JScrollPane();
		
		btnGeraRelatorioAtendido = new JButton("Gerar");
		btnGeraRelatorioAtendido.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(jtAtendidoRelatorio.getSelectedRow() < 0){
					Visao.showMessageError(EnumMensagens.MSG_ALERTA_ATENDIDO_N_SELECIONADO.getMensagem(), "Aviso");
					return;
				}else
					RelatoriosUtil.quantidadeDeAtendimentosAtendidosByAFI(dpRAtendidoInicio.getDate(), dpRAtendidoFim.getDate(), modeloTabelaPaciente.getPessoaAt(jtAtendidoRelatorio.getSelectedRow()),getTrabalhador());
			}
		});
		btnGeraRelatorioAtendido.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/Report-48.png")));
		GroupLayout gl_painelAtendidoRelatorio = new GroupLayout(painelAtendidoRelatorio);
		gl_painelAtendidoRelatorio.setHorizontalGroup(
			gl_painelAtendidoRelatorio.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_painelAtendidoRelatorio.createSequentialGroup()
					.addGroup(gl_painelAtendidoRelatorio.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_painelAtendidoRelatorio.createSequentialGroup()
							.addContainerGap()
							.addGroup(gl_painelAtendidoRelatorio.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_painelAtendidoRelatorio.createSequentialGroup()
									.addComponent(lblAtendidoRelatorio)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(txtBuscaAtendido, GroupLayout.PREFERRED_SIZE, 262, GroupLayout.PREFERRED_SIZE))
								.addComponent(painelPeriodoAtendidoR, GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
								.addComponent(spAtendidoRelatorio, GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)))
						.addGroup(gl_painelAtendidoRelatorio.createSequentialGroup()
							.addGap(318)
							.addComponent(btnGeraRelatorioAtendido)))
					.addContainerGap())
		);
		gl_painelAtendidoRelatorio.setVerticalGroup(
			gl_painelAtendidoRelatorio.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelAtendidoRelatorio.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelAtendidoRelatorio.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblAtendidoRelatorio)
						.addComponent(txtBuscaAtendido, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(spAtendidoRelatorio, GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
					.addGap(18)
					.addComponent(painelPeriodoAtendidoR, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
					.addGap(12)
					.addComponent(btnGeraRelatorioAtendido)
					.addGap(34))
		);
		
		jtAtendidoRelatorio = new JTable();
		jtAtendidoRelatorio.setModel(modeloTabelaPaciente);
		zeraPreencheTabelaAtendidoRelatorio();
		spAtendidoRelatorio.setViewportView(jtAtendidoRelatorio);
		painelAtendidoRelatorio.setLayout(gl_painelAtendidoRelatorio);
		painelRelatorio.setLayout(gl_painelRelatorio);
		
		painelInicial = new JPanel();
		painelInicial.setBackground(Color.WHITE);
		
		JLabel lblLogo = new JLabel("");
		lblLogo.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/cebg2.jpg")));
		GroupLayout gl_painelInicial = new GroupLayout(painelInicial);
		gl_painelInicial.setHorizontalGroup(
			gl_painelInicial.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelInicial.createSequentialGroup()
					.addGap(207)
					.addComponent(lblLogo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(207))
		);
		gl_painelInicial.setVerticalGroup(
			gl_painelInicial.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelInicial.createSequentialGroup()
					.addGap(90)
					.addComponent(lblLogo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(91))
		);
		painelInicial.setLayout(gl_painelInicial);
		
		painelAtendimentos = new JPanel();
		painelAtendimentos.setVisible(false);
		
		JScrollPane spAtendimentos = new JScrollPane();
		
		cabecario = new JPanel();
		cabecario.setBorder(new LineBorder(new Color(0, 0, 0)));
		GroupLayout gl_painelAtendimentos = new GroupLayout(painelAtendimentos);
		gl_painelAtendimentos.setHorizontalGroup(
			gl_painelAtendimentos.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelAtendimentos.createSequentialGroup()
					.addGroup(gl_painelAtendimentos.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_painelAtendimentos.createSequentialGroup()
							.addGap(6)
							.addComponent(cabecario, GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE))
						.addGroup(gl_painelAtendimentos.createSequentialGroup()
							.addContainerGap()
							.addComponent(spAtendimentos, GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE)))
					.addContainerGap())
		);
		gl_painelAtendimentos.setVerticalGroup(
			gl_painelAtendimentos.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_painelAtendimentos.createSequentialGroup()
					.addComponent(cabecario, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(9)
					.addComponent(spAtendimentos, GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE))
		);
		
		painelData = new JPanel();
		painelData.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		painelQuantAtned = new JPanel();
		painelQuantAtned.setBorder(new LineBorder(new Color(0, 0, 0)));
		GroupLayout gl_cabecario = new GroupLayout(cabecario);
		gl_cabecario.setHorizontalGroup(
			gl_cabecario.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_cabecario.createSequentialGroup()
					.addContainerGap()
					.addComponent(painelData, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(painelQuantAtned, GroupLayout.PREFERRED_SIZE, 299, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(267, Short.MAX_VALUE))
		);
		gl_cabecario.setVerticalGroup(
			gl_cabecario.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_cabecario.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_cabecario.createParallelGroup(Alignment.TRAILING)
						.addComponent(painelQuantAtned, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
						.addComponent(painelData, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
					.addContainerGap())
		);
		dpSistemaAFI = new JXDatePicker();
		dpSistemaAFI.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				modificaTela();
				
			}
		});
		lblQuantidadeDeAtendimentos_1 = new JLabel("Quantidade de Atendimentos do Mês de "+DateUtil.getNomeMes(dpSistemaAFI.getDate()));
		AtendimentoModel model = new AtendimentoModelImpl();
		lblQuantAtend = new JLabel(model.getQuantAtendimentoAfiDate(getTrabalhador().getCpf(),dpSistemaAFI.getDate()).toString());
		lblQuantAtend.setFont(new Font("Times New Roman", Font.PLAIN, 30));
		GroupLayout gl_painelQuantAtned = new GroupLayout(painelQuantAtned);
		gl_painelQuantAtned.setHorizontalGroup(
			gl_painelQuantAtned.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelQuantAtned.createSequentialGroup()
					.addGroup(gl_painelQuantAtned.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_painelQuantAtned.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblQuantidadeDeAtendimentos_1))
						.addGroup(gl_painelQuantAtned.createSequentialGroup()
							.addGap(137)
							.addComponent(lblQuantAtend)))
					.addContainerGap(8, Short.MAX_VALUE))
		);
		gl_painelQuantAtned.setVerticalGroup(
			gl_painelQuantAtned.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_painelQuantAtned.createSequentialGroup()
					.addContainerGap(15, Short.MAX_VALUE)
					.addComponent(lblQuantidadeDeAtendimentos_1)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(lblQuantAtend)
					.addContainerGap())
		);
		painelQuantAtned.setLayout(gl_painelQuantAtned);
		
		lblData = new JLabel("Data:");
		
		
		GroupLayout gl_painelData = new GroupLayout(painelData);
		gl_painelData.setHorizontalGroup(
			gl_painelData.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_painelData.createSequentialGroup()
					.addContainerGap(22, Short.MAX_VALUE)
					.addGroup(gl_painelData.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_painelData.createSequentialGroup()
							.addGap(46)
							.addComponent(lblData))
						.addComponent(dpSistemaAFI, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(19))
		);
		gl_painelData.setVerticalGroup(
			gl_painelData.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_painelData.createSequentialGroup()
					.addContainerGap(16, Short.MAX_VALUE)
					.addComponent(lblData)
					.addGap(6)
					.addComponent(dpSistemaAFI, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(11))
		);
		painelData.setLayout(gl_painelData);
		cabecario.setLayout(gl_cabecario);
		
		jtableAtendimentos = new JTable();
		jtableAtendimentos.setModel(modeloTabelaAtendimentoGerencia);
		spAtendimentos.setViewportView(jtableAtendimentos);
		jtableAtendimentos.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				if(e.getClickCount() == 2)
					switch (jtableAtendimentos.getSelectedColumn()) {
					case 6:
						JanelaTipoAtendimento.setIdAtendimento(modeloTabelaAtendimentoGerencia.getAtendimentoAt(jtableAtendimentos.getSelectedRow()).getIdAtendimento());
						ControladorJanelas.invokeJDialog(this.getClass().getSimpleName(), EnumControleJanela.JANELA_TIPO_ATENDIMENTO.getNomeJanela());
						break;
					case 7:
						JanelaEncaminhamento.setIdAtendimento(modeloTabelaAtendimentoGerencia.getAtendimentoAt(jtableAtendimentos.getSelectedRow()).getIdAtendimento());
						ControladorJanelas.invokeJDialog(this.getClass().getSimpleName(), EnumControleJanela.JANELA_ENCAMINHAMENTO.getNomeJanela());
						break;
					}
			}
		});
		zeraPreencheTabelaAtendimento();
		painelAtendimentos.setLayout(gl_painelAtendimentos);
		
		txtNome = new JTextField();
		txtNome.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		txtNome.setColumns(10);
		txtNome.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
					if(!Validadores.validaString(txtNome.getText())){
						txtNome.setForeground(Color.RED);
					}
					else
						txtNome.setForeground(Color.BLUE);
			}
		});
		lblNome = new JLabel("Nome:");
		lblNome.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		lblCpf = new JLabel("CPF:");
		lblCpf.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		ftxtCPF = new JFormattedTextField();
		ftxtCPF.setEditable(false);
		ftxtCPF.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		try {
			ftxtCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
		} catch (ParseException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		ftxtCPF.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getClickCount() == 2)
					Visao.showMessageWarning(EnumMensagens.MSG_ALERTA_CPF_N_ALTERADO.getMensagem(),"Aviso");
			}
		});
		lblDataDeNasc = new JLabel("Data de Nasc:");
		lblDataDeNasc.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		ftxtDataNasc = new JFormattedTextField();
		ftxtDataNasc.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		try {
			ftxtDataNasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
		} catch (ParseException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		ftxtDataNasc.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
					if(!Validadores.validaData(ftxtDataNasc.getText()))
						ftxtDataNasc.setForeground(Color.RED);
					else
						ftxtDataNasc.setForeground(Color.BLUE);
			}
		});
		lblSexo = new JLabel("Sexo:");
		lblSexo.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		lblEndereo = new JLabel("Endereço:");
		lblEndereo.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		txtEndereco = new JTextField();
		txtEndereco.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		txtEndereco.setColumns(10);
		txtEndereco.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
					if(!Validadores.validaString(txtEndereco.getText()))
						txtEndereco.setForeground(Color.RED);
					else
						txtEndereco.setForeground(Color.BLUE);
			}
		});
		lblTelefones = new JLabel("Telefones:");
		lblTelefones.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		lblEmail = new JLabel("Email:");
		lblEmail.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		txtEmail = new JTextField();
		txtEmail.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		txtEmail.setColumns(10);
		txtEmail.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
					if(!Validadores.validaEmail(txtEmail.getText()))
						txtEmail.setForeground(Color.RED);
					else
						txtEmail.setForeground(Color.BLUE);
			}
		});
		lblCdScio = new JLabel("Cod. Sócio:");
		lblCdScio.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		
		txtCodSocio = new JTextField();
		txtCodSocio.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		txtCodSocio.setColumns(10);
		txtCodSocio.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
					if(!Validadores.validaString(txtCodSocio.getText()))
						txtCodSocio.setForeground(Color.RED);
					else
						txtCodSocio.setForeground(Color.BLUE);
			}
		});
		JPanel painel_Sexo = new JPanel();
		painel_Sexo.setBorder(UIManager.getBorder("TitledBorder.border"));
		
		JPanel painelInformacoes = new JPanel();
		painelInformacoes.setBorder(UIManager.getBorder("TitledBorder.border"));
		painelTelefones = new JPanel();
		painelTelefones.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		
		JPanel painelOpcoes = new JPanel();
		painelOpcoes.setBorder(new TitledBorder(null, "Opções", TitledBorder.LEFT, TitledBorder.ABOVE_TOP, null, null));
		
		GroupLayout gl_painelAlteraPerfil = new GroupLayout(painelAlteraPerfil);
		gl_painelAlteraPerfil.setHorizontalGroup(
			gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
					.addGap(24)
					.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addComponent(lblDataDeNasc)
							.addGap(18)
							.addComponent(ftxtDataNasc, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNome)
								.addComponent(lblCpf))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(ftxtCPF, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)
								.addComponent(txtNome, GroupLayout.PREFERRED_SIZE, 285, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(lblEndereo)
								.addComponent(lblSexo))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(painel_Sexo, GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)
								.addComponent(txtEndereco, 289, 289, 289)))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addComponent(lblEmail)
							.addGap(43)
							.addComponent(txtEmail, 287, 287, 287))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(lblCdScio)
								.addComponent(lblTelefones))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(painelTelefones, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(txtCodSocio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addGap(48)
							.addComponent(painelInformacoes, GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(painelOpcoes, GroupLayout.PREFERRED_SIZE, 221, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_painelAlteraPerfil.setVerticalGroup(
			gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
					.addGap(48)
					.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNome)
								.addComponent(txtNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblCpf)
								.addComponent(ftxtCPF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblDataDeNasc)
								.addComponent(ftxtDataNasc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
									.addGap(18)
									.addComponent(painel_Sexo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
									.addGap(35)
									.addComponent(lblSexo)))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblEndereo)
								.addComponent(txtEndereco, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblEmail)
								.addComponent(txtEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblCdScio)
								.addComponent(txtCodSocio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(gl_painelAlteraPerfil.createParallelGroup(Alignment.LEADING)
								.addComponent(painelTelefones, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblTelefones)))
						.addGroup(gl_painelAlteraPerfil.createSequentialGroup()
							.addComponent(painelInformacoes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(painelOpcoes, GroupLayout.PREFERRED_SIZE, 228, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(24, Short.MAX_VALUE))
		);
		
		btnAlterar = new JButton("Salvar Alterações");
		btnAlterar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(TrabalhadorUtil.alteraTrabalhador(getTrabalhador().getId(),
											  txtNome.getText(),
											  txtEndereco.getText(),
											  txtEmail.getText(),
											  txtCodSocio.getText(),
											  ftxtDataNasc.getText(),
											  ftxtTel1.getText(),
											  ftxtTel2.getText(),
											  ftxtTel3.getText(),
											  ftxtTel4.getText(),
											  ftxtTel5.getText(),
											  ftxtTel6.getText(),
											  rdbtnMasculino
											 )){
					Visao.showMessage(EnumMensagens.MSG_CONFIRMACAO_ALTERACAO_SUCESSO.getMensagem(), "Aviso");
					painelAlteraPerfil.setVisible(false);
					painelInicial.setVisible(true);
				}
			
				
			}
		});
		btnAlterar.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/iconSalvar.png")));
		
		btnCancelar = new JButton("Fechar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				preparaPainelPrincipal();
				painelInicial.setVisible(true);
			}
		});
		btnCancelar.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/iconCancelar.png")));
		
		btnAlterarSenha = new JButton("Alterar Senha");
		btnAlterarSenha.setIcon(new ImageIcon(JanelaAFI.class.getResource("/br/ucb/cesbdao/imagens/iconModificar.png")));
		btnAlterarSenha.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ControladorJanelas.invokeJDialog(this.getClass().getSimpleName(), EnumControleJanela.JANELA_ALTERA_SENHA.getNomeJanela());
			}
		});
		GroupLayout gl_painelOpcoes = new GroupLayout(painelOpcoes);
		gl_painelOpcoes.setHorizontalGroup(
			gl_painelOpcoes.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_painelOpcoes.createSequentialGroup()
					.addContainerGap(31, Short.MAX_VALUE)
					.addGroup(gl_painelOpcoes.createParallelGroup(Alignment.LEADING)
						.addComponent(btnCancelar)
						.addComponent(btnAlterar)
						.addComponent(btnAlterarSenha))
					.addGap(11))
		);
		gl_painelOpcoes.setVerticalGroup(
			gl_painelOpcoes.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelOpcoes.createSequentialGroup()
					.addContainerGap()
					.addComponent(btnAlterar)
					.addGap(18)
					.addComponent(btnAlterarSenha)
					.addGap(18)
					.addComponent(btnCancelar)
					.addContainerGap(53, Short.MAX_VALUE))
		);
		gl_painelOpcoes.linkSize(SwingConstants.VERTICAL, new Component[] {btnAlterar, btnCancelar, btnAlterarSenha});
		gl_painelOpcoes.linkSize(SwingConstants.HORIZONTAL, new Component[] {btnAlterar, btnCancelar, btnAlterarSenha});
		painelOpcoes.setLayout(gl_painelOpcoes);
		
		ftxtTel1 = new JFormattedTextField();
		ftxtTel1.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if(!Validadores.validaTelefone(ftxtTel1.getText()))
					ftxtTel1.setForeground(Color.RED);
				else
					ftxtTel1.setForeground(Color.BLUE);
			}
		});
		try {
			ftxtTel1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}		
		ftxtTel2 = new JFormattedTextField();
		try {
			ftxtTel2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}
		ftxtTel3 = new JFormattedTextField();
		try {
			ftxtTel3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}
		ftxtTel4 = new JFormattedTextField();
		try {
			ftxtTel4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}
		ftxtTel5 = new JFormattedTextField();
		try {
			ftxtTel5.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}
		ftxtTel6 = new JFormattedTextField();
		try {
			ftxtTel6.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
		} catch (ParseException e1) {
			logger.error(e1.getMessage());
			e1.printStackTrace();
		}
		lblSeparador = new JLabel(",");
		
		lblSeparador2 = new JLabel(",");
		
		lblSeparador3 = new JLabel(",");
		
		lblSeparador4 = new JLabel(",");
		GroupLayout gl_painelTelefones = new GroupLayout(painelTelefones);
		gl_painelTelefones.setHorizontalGroup(
			gl_painelTelefones.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelTelefones.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelTelefones.createParallelGroup(Alignment.LEADING, false)
						.addGroup(gl_painelTelefones.createSequentialGroup()
							.addComponent(ftxtTel1, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblSeparador)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(ftxtTel2, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblSeparador2)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(ftxtTel3, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_painelTelefones.createSequentialGroup()
							.addComponent(ftxtTel4, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblSeparador3)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(ftxtTel5, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblSeparador4)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(ftxtTel6, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_painelTelefones.setVerticalGroup(
			gl_painelTelefones.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelTelefones.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelTelefones.createParallelGroup(Alignment.BASELINE)
						.addComponent(ftxtTel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ftxtTel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ftxtTel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblSeparador)
						.addComponent(lblSeparador2))
					.addGap(18)
					.addGroup(gl_painelTelefones.createParallelGroup(Alignment.BASELINE)
						.addComponent(ftxtTel4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ftxtTel5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ftxtTel6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblSeparador3)
						.addComponent(lblSeparador4))
					.addContainerGap(17, Short.MAX_VALUE))
		);
		gl_painelTelefones.linkSize(SwingConstants.VERTICAL, new Component[] {ftxtTel1, ftxtTel2, ftxtTel3, ftxtTel4, ftxtTel5, ftxtTel6});
		gl_painelTelefones.linkSize(SwingConstants.HORIZONTAL, new Component[] {ftxtTel1, ftxtTel2, ftxtTel3, ftxtTel4, ftxtTel5, ftxtTel6});
		painelTelefones.setLayout(gl_painelTelefones);
		
		JLabel lblQuantidadeDeAtendimentos = new JLabel("Quantidade de Atendimentos:");
		lblQuant_1 = new JLabel(model.getQuantAtendimentoAFI(DadosSessaoUser.getInstance().getCPF()).toString());
		GroupLayout gl_painelInformacoes = new GroupLayout(painelInformacoes);
		gl_painelInformacoes.setHorizontalGroup(
			gl_painelInformacoes.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelInformacoes.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblQuantidadeDeAtendimentos)
					.addGap(18)
					.addComponent(lblQuant_1)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		gl_painelInformacoes.setVerticalGroup(
			gl_painelInformacoes.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_painelInformacoes.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_painelInformacoes.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblQuantidadeDeAtendimentos)
						.addComponent(lblQuant_1))
					.addContainerGap(149, Short.MAX_VALUE))
		);
		painelInformacoes.setLayout(gl_painelInformacoes);
		
		rdbtnMasculino = new JRadioButton("Masculino");
		btnGroupSexo.add(rdbtnMasculino);
		rdbtnMasculino.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		painel_Sexo.add(rdbtnMasculino);
		
		rdbtnFeminino = new JRadioButton("Feminino");
		btnGroupSexo.add(rdbtnFeminino);
		rdbtnFeminino.setFont(new Font("Times New Roman", Font.PLAIN, 13));
		painel_Sexo.add(rdbtnFeminino);
		painelAlteraPerfil.setLayout(gl_painelAlteraPerfil);
		GroupLayout gl_layeredPane = new GroupLayout(layeredPane);
		gl_layeredPane.setHorizontalGroup(
			gl_layeredPane.createParallelGroup(Alignment.LEADING)
				.addComponent(painelAtendimentos, GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
				.addComponent(painelInicial, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(painelRelatorio, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addGroup(gl_layeredPane.createSequentialGroup()
					.addGap(6)
					.addComponent(painelAlteraPerfil, GroupLayout.PREFERRED_SIZE, 762, Short.MAX_VALUE)
					.addGap(6))
		);
		gl_layeredPane.setVerticalGroup(
			gl_layeredPane.createParallelGroup(Alignment.LEADING)
				.addComponent(painelAtendimentos, GroupLayout.PREFERRED_SIZE, 529, Short.MAX_VALUE)
				.addComponent(painelInicial, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(painelRelatorio, GroupLayout.PREFERRED_SIZE, 529, Short.MAX_VALUE)
				.addGroup(gl_layeredPane.createSequentialGroup()
					.addGap(6)
					.addComponent(painelAlteraPerfil, GroupLayout.PREFERRED_SIZE, 517, Short.MAX_VALUE)
					.addGap(6))
		);
		layeredPane.setLayout(gl_layeredPane);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addComponent(layeredPane)
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addComponent(layeredPane)
		);
		contentPane.setLayout(gl_contentPane);
		
	}
	private void zeraPreencheTabelaAtendidoRelatorio() {
		modeloTabelaPaciente = new ModeloTabelaPaciente();
		jtAtendidoRelatorio.setModel(modeloTabelaPaciente);
		jtAtendidoRelatorio.getTableHeader().setReorderingAllowed(false);
		jtAtendidoRelatorio.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		jtAtendidoRelatorio.setAutoCreateRowSorter(true);
		AtendidoModel model = new AtendidoModelImpl();
		modeloTabelaPaciente.setPacientes(model.consultaPacienteByNome(txtBuscaAtendido.getText()));
	}
	protected void preparaPainelPrincipal() {
		painelAlteraPerfil.setVisible(false);
		painelAtendimentos.setVisible(false);
		painelRelatorio.setVisible(false);
		painelInicial.setVisible(false);
	}
	protected void modificaTela() {
		zeraPreencheTabelaAtendimento();
		AtendimentoModel model = new AtendimentoModelImpl();
		lblQuantidadeDeAtendimentos_1.setText("Quantidade de Atendimentos do Mês de "+DateUtil.getNomeMes(dpSistemaAFI.getDate()));
		lblQuantAtend.setText(model.getQuantAtendimentoAfiDate(getTrabalhador().getCpf(),dpSistemaAFI.getDate()).toString());
	}
	private void zeraPreencheTabelaAtendimento() {
		modeloTabelaAtendimentoGerencia = new ModeloTabelaAtendimentoGerencia();
		jtableAtendimentos.setModel(modeloTabelaAtendimentoGerencia);
		jtableAtendimentos.getTableHeader().setReorderingAllowed(false);
		jtableAtendimentos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		jtableAtendimentos.setAutoCreateRowSorter(true);
		AtendimentoModel model = new AtendimentoModelImpl();
		modeloTabelaAtendimentoGerencia.setAtendimento(model.getByAfiDate(getTrabalhador(),dpSistemaAFI.getDate()));
	}
	
	private void setAfi() {
		TrabalhadorModel model = new TrabalhadorModelImpl();
		setTrabalhador(model.consultaTrabalhadorByCpf(DadosSessaoUser.getInstance().getCPF()));
		txtNome.setText(getTrabalhador().getNome());
		txtEmail.setText(getTrabalhador().getEmail());
		txtCodSocio.setText(getTrabalhador().getIdSocio().toString());
		ftxtCPF.setText(getTrabalhador().getCpf());
		txtEndereco.setText(getTrabalhador().getEndereco());
		ftxtDataNasc.setText(DateUtil.formatDateOut(getTrabalhador().getDataNascimento()));
		if(getTrabalhador().getSexo() == 'M')
			rdbtnMasculino.setSelected(true);
		else
			rdbtnFeminino.setSelected(true);
		ArrayList<String> telefones = TrabalhadorUtil.pegaTelefone(getTrabalhador().getTelefone());
		try {
			ftxtTel1.setText(telefones.get(0));
			ftxtTel2.setText(telefones.get(1));
			ftxtTel3.setText(telefones.get(2));
			ftxtTel4.setText(telefones.get(3));
			ftxtTel5.setText(telefones.get(4));
			ftxtTel6.setText(telefones.get(5));
		} catch (IndexOutOfBoundsException e) {
			logger.error(e.getMessage());
		}
		
	}
	public static Trabalhador getTrabalhador() {
		return atendente;
	}

	public static void setTrabalhador(Trabalhador atendente) {
		JanelaAFI.atendente = atendente;
	}
	public static Logger getLogger() {
		return logger;
	}
	public static void setLogger(Logger logger) {
		JanelaAFI.logger = logger;
	}
}
